package net.homeip.jcperera.nu.security.credential;

import javax.inject.Named;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Embeddable;

/**
 * Password, in combination with Login, referring to the most widely used identification method
 * 
 * @name Password class
 * @author julio.c.perera@gmail.com
 * @application nu
 * @since 0.1.0.0
 */

@Named(Password.componentName)
@Embeddable
public class Password extends Credential
{
    // Required to implement Serializable interfac
    private static final long  serialVersionUID = 499895283150463539L;

    // CoreBase properties, for easy use from other components, as well as logging
    public static final int    runtimeLevel     = 2;
    public static final String moduleName       = "security";
    public static final String componentName    = "nu_security_credential";

    /**
     * Default constructor, initially sets a blank password
     */
    public Password()
    {
        setValue("");
    }

    /**
     * @param initialValue
     */
    public Password(String initialValue)
    {
        setValue(initialValue.trim());
    }

    /**
     * @param valueToVerify
     */
    @Override
    public boolean verify(Credential valueToVerify)
    {
        return verify(valueToVerify.toString());
    }

    /**
     * @param valueToVerify
     */
    public boolean verify(String valueToVerify)
    {
        return valueToVerify.trim().equals(getValue());
    }

    /**
     * @param initialValue
     */
    public void Credential(Object initialValue)
    {
        setValue(initialValue.toString().trim());
    }

    /**
     * Gets the current value of the current credential, for persistence related functionality (mostly), you should not
     * use this value to make comparisons, but use the method {@link #verify()} instead
     */
    @Override
    @Basic
    @Column(name = "password")
    public String getValue()
    {
        return super.getValue();
    }
}